#include <iostream>
#include <unistd.h>
#include <string>
#include <memory>
#include <ctime>
#include "ThreadPool.hpp"
#include "Task.hpp"
#include "Log.hpp"

// int main()
// {
//     LOG(DEBUG,"程序加载");
//     sleep(3);
//     ThreadPool<Task>::GetInstance();
//     sleep(2);

//     ThreadPool<Task>::GetInstance();
//     sleep(2);

//     ThreadPool<Task>::GetInstance();
//     sleep(2);

//     ThreadPool<Task>::GetInstance();
//     sleep(2);

//     ThreadPool<Task>::GetInstance()->Wait();
//     sleep(2);

//     return 0;
// }

int main()
{
    srand(time(nullptr) ^ getpid() ^ pthread_self());
    EnableScreen();
    std::unique_ptr<ThreadPool<Task>> tp = std::make_unique<ThreadPool<Task>>(5); // c++14创建智能指针
    tp->InitThreadPool();
    tp->Start();

    int tasknum = 10;
    while (tasknum)
    {
        int a = rand() % 10 + 1;
        usleep(1234);
        int b = rand() % 5 + 1;
        Task t(a, b);
        LOG(INFO, "main thread push task: %s", t.DebugToString().c_str());
        tp->Enqueue(t);
        sleep(1);
        tasknum--;
    }

    tp->Stop();
    tp->Wait();
}